--- title: "L2-020 功夫传人" created: 2025-11-28 tags: - 算法 --- # L2-020 功夫传人 ## 题目 [L2-020 功夫传人](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=994805059118809088&page=1) ![[image-5f03eb07.png]] ## 思路分析 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1}; const int inf = 0x3f3f3f3f; priority_queue pq; multiset s; struct People{ int king=1; vector child; }; vector person; int n; double r,z,res=0; void dfs(int u,double k){ if(person[u].king!=1){ k*=person[u].king; res+=k; } for(auto nxt:person[u].child){ double nxtk=k*(100-r)/100; dfs(nxt,nxtk); } } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>z>>r; person.resize(n); for(int i=0;i>k; if(k==0){ cin>>person[i].king; }else{ while(k--){ int t;cin>>t; person[i].child.push_back(t); } } } dfs(0,z); cout<<(int)res; return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[L2-019 悄悄关注|L2-019 悄悄关注]] 🏠 [[00-天梯赛]] ➡️ [[L2-021 点赞狂魔|L2-021 点赞狂魔]]